<!--<link rel="stylesheet" href="<?php echo $baseurl;?>assets/chosen_v1.4.2/style.css">-->
<link rel="stylesheet" href="<?php echo $baseurl;?>assets/chosen_v1.4.2/prism.css">
<link rel="stylesheet" href="<?php echo $baseurl;?>assets/chosen_v1.4.2/chosen.css">
<style type="text/css" media="all">
    .chosen-rtl .chosen-drop { left: -9000px; }
</style>
<div id="sidetabs_body_container">
<?php if(validation_errors() || @$error || @$zero):?>
    <div id="error_container" style='display:block'>
        <div class="notice_explanation_container">
            <div class="notice_explanation bad">
                <strong>Oh lỗi!</strong>&nbsp;&nbsp;<?php echo validation_errors(); ?>
                <?php if(@$error):?>
                <br />
                <?php echo $error?>
                <?php endif;?>
            </div>
        </div>
    </div>
<?php endif;?>
    
    <div class="main_container">
        <div id="detail_header">
          <table class="lean">
            <tbody><tr>
              <td style="padding:5px 10px 0 0" colspan="2"><a href="<?php echo $baseurl?>admin-system.html" id="list_link">Quản lý admin thiết bị</a>&nbsp;›
              </td>
              <td>
                <h1 class="db s3name">Danh sách admin thiết bị</h1>
              </td>
            </tr>
          </tbody></table>
        
          <hr style="clear:both" class="s3"/>
        </div>
        <div id="detail_area">
            <div class="hideport3" id="details_wrapper">
                <div class="left-pos">
                    <?php $attr = array('class' => 'form-target'); echo form_open('', $attr);?>
                    <table class="s3basicedit wiform">
                       <tbody>
                          <tr>
                             <td colspan="2">
                                <h2 class="s3">Thêm admin thiết bị</h2>
                                <hr style="margin-top: -2px" class="s3"/>
                             </td>
                          </tr>
                          <tr class="base">
                            <input type="hidden" name="id" value="0"/>
                            <input type="hidden" name="type" value="add"/>
                          </tr>
                          <tr class="top">
                             <td class="s3l align-right">Tên đăng nhập <span style="color: red;">(*)</span>:</td>
                             <td class="s3w"><input autocomplete="off" type="text" value="<?php echo $this->input->post('username')?>" name="username" id="username" class="w99"/></td>
                          </tr>
                          <tr class="top">
                             <td class="s3l align-right">Mật khẩu <span style="color: red;">(*)</span>:</td>
                             <td class="s3w"><input autocomplete="off" type="password" value="<?php echo $this->input->post('password')?>" name="password" id="password" class="w99"/></td>
                          </tr>
						  <tr class="top">
                             <td class="s3l align-right">Địa chỉ email <span style="color: red;">(*)</span>:</td>
                             <td class="s3w"><input type="text" value="<?php echo $this->input->post('email')?>" name="email" id="email" class="w99"/></td>
                          </tr>
						  <tr class="top">
                             <td class="s3l align-right">Số điện thoại <span style="color: red;">(*)</span>:</td>
                             <td class="s3w"><input type="text" value="<?php echo $this->input->post('mobile')?>" name="mobile" id="mobile" class="w99"/></td>
                          </tr>
						  <tr class="top">
                             <td class="s3l align-right">Họ tên <span style="color: red;">(*)</span>:</td>
                             <td class="s3w"><input type="text" value="<?php echo $this->input->post('fullname')?>" name="fullname" id="fullname" class="w99"/></td>
                          </tr>
						  
				          <tr class="top">
                             <td class="s3l align-right">Nhóm quản lý <span style="color: red;">(*)</span>:</td>
                             <td class="s3w">
                                <?php echo $fview->selectOptionOb($getGroup, $this->input->post('manage_group_id'), 'w99', 'manage_group_id', 'manage_group_id');?>
                             </td>
                          </tr> 
						  
						  
                         <tr id="" class="top" <?php if( $this->session->userdata('level') == 1 ){ ?> style="display:;" <?php } ?> >
                             <td class="s3l align-right">Thiết bị quản lý <span style="color: red;">(*)</span>:</td>
                             <td class="s3w" id="thietbiquanly">
                                <select data-placeholder="Chọn thiết bị..." name="arr_device_id[]" id="arr_device_id" class="chosen-select" multiple="multiple" style="width:350px;" tabindex="4">
                                <option value=""></option>
                                <?php  ?>
                                <?php foreach ( $getDevice AS $el=>$le ){ ?> 
                                <option value="<?php echo $le->id;?>"><?php echo $le->namedevice;?></option>
                                <?php } ?>
                                
                                </select>
                             </td>
                          </tr>
                          <tr class="top">
                             <td class="s3l align-right">Đồng bộ Wicity ?</td>
                             <td class="s3w">
                                <input type="checkbox" name="sync" id="sync" value="1"/>
                             </td>
                          </tr> 
                          <tr class="base">
                             <td colspan="2" class="s3actions">
                                <div>
                                   <table style="margin: 0.5ex auto 0.5ex auto" class="lean">
                                      <tbody>
                                         <tr>
                                            <td><input type="submit" id="submit" value="Tạo mới"/> <input class="cancelaj" type="reset" value="Làm lại"/></td>
                                         </tr>
                                      </tbody>
                                   </table>
                                </div>
                             </td>
                          </tr>
                       </tbody>
                    </table>
                    </form>
                </div>
                <div class="right-pos">
                    <div style="position:relative" id="client_table" class="flex-table add_col">
                       <table class="filter compact fill">
                       <colgroup>
                             <col>
                             <col width="0*">
                             <col>
                             <col>
                             <col>
                             <col>
                             <col>
                             <col>
                          </colgroup>
                          <thead>
                             <tr class="ft_head">
                                <th class="ft ftl checkbox nodrag checknum checkbox ftlegend" style="width:40px"><input type="checkbox" class="check_all"/></th>
                                <th class="ft ftl undefined nodrag name ftsortable">
                                   <table class="lean">
                                      <tbody>
                                         <tr style="vertical-align:bottom">
                                            <td class="ftlegend">Tên đăng nhập</td>
                                            <td style="padding:0 5px"></td>
                                         </tr>
                                      </tbody>
                                   </table>
                                </th>
                                <th class="ft ftl undefined nodrag name ftsortable">
                                   <table class="lean">
                                      <tbody>
                                         <tr style="vertical-align:bottom">
                                            <td class="ftlegend">Họ tên</td>
                                            <td style="padding:0 5px"></td>
                                         </tr>
                                      </tbody>
                                   </table>
                                </th>
								<th class="ft ftl undefined nodrag name ftsortable">
                                   <table class="lean">
                                      <tbody>
                                         <tr style="vertical-align:bottom">
                                            <td class="ftlegend">Email</td>
                                            <td style="padding:0 5px"></td>
                                         </tr>
                                      </tbody>
                                   </table>
                                </th>
								<th class="ft ftl undefined nodrag name ftsortable">
                                   <table class="lean">
                                      <tbody>
                                         <tr style="vertical-align:bottom">
                                            <td class="ftlegend">Nhóm mạng</td>
                                            <td style="padding:0 5px"></td>
                                         </tr>
                                      </tbody>
                                   </table>
                                </th>
                                <th class="ft ftl undefined nodrag name ftsortable">
                                   <table class="lean">
                                      <tbody>
                                         <tr style="vertical-align:bottom">
                                            <td class="ftlegend">Thiết bị</td>
                                            <td style="padding:0 5px"></td>
                                         </tr>
                                      </tbody>
                                   </table>
                                </th>
                                <th class="ft ftl action ftsortable">
                                   <table class="lean">
                                      <tbody>
                                         <tr style="vertical-align:bottom">
                                            <td class="ftlegend">Tác vụ</td>
                                            <td style="padding:0 5px"></td>
                                         </tr>
                                      </tbody>
                                   </table>
                                </th>
                             </tr>
                          </thead>
                          <tfoot>
                             <tr class="ft_foot">
                                <td colspan="7" class="ft_foot">
                                   <table class="ft_foot">
                                      <tfoot>
                                         <tr class="ft_foot">
                                            <td class="pgnum">
                                                <?php echo $this->pagination->create_links();?>
                                            </td>
                                         </tr>
                                      </tfoot>
                                   </table>
                                </td>
                             </tr>
                          </tfoot>
                          <tbody>
                            <?php
                                if($page_current != 0){
                            	   $page_current = $page_current - 1;
                            	}
                                 
                                $i = 1;
                                foreach($data AS $key => $value):?>
                            <?php
                            
                                $stt = $page_current * $_per_page + $i;

                                $ss = $stt % 2;
                                if ($ss == 0){
                                    $class = 'ftp1';
                                }else{
                                    $class = 'ftp0';
                                }
                            ?>
                            <tr data-idx="<?php echo $stt?>" class="<?php echo $class?>">
                                <td class="ft checkbox nodrag checknum"><input type="checkbox" class="row_check"/>&nbsp;<?php echo $stt?></td>
                                <td class="ft undefined nodrag"><?php echo stripslashes($value->username)?></td>
                                <td class="ft undefined nodrag"><?php echo $value->fullname?></td>
								<td class="ft undefined nodrag"><?php echo $value->email?></td>
								<td class="ft undefined nodrag"><?php echo $value->group_name ? $value->group_name : '<span style="color: #FF0079">Chưa thiết lập</span>'?></td>
                                <td class="ft undefined nodrag">
                                <?php if($value->device):?>
                                    <?php foreach($value->device AS $keys => $vals):?>
                                        <?php echo $vals->namedevice.', ';?>
                                    <?php endforeach;?>
                                <?php else:?> 
                                    <?php echo '<span style="color: #FF0079">Chưa thiết lập</span>';?>
                                <?php endif;?>
                                </td>
                                <td class="ft undefined nodrag">
                                    <a data-id="<?php echo $value->id?>" class="editaj" href="#">Sửa</a> | <a class="deleteaj" href="<?php echo $baseurl?>delete-admin-device?id=<?php echo $value->id?>">Xóa</a>
                                </td>
                             </tr>
                            <?php $i++; endforeach;?>
                          </tbody>
                       </table>
                    </div>
                </div>
            </div>
        </div>

    </div>

</div>


 
<script type="text/javascript">
    $(document).ready(function(){
        $(document).on('change', '#manage_group_id', function(){
           var manage_group_id = $(this).val();
		   $.ajax({
                type: 'GET',
                url: baseUrl + 'get-list-device',
                data: ({id: manage_group_id}),
                success: function(data)
                {
					$("#thietbiquanly").html(data);
                }
           });
        }); 
        
        $(document).on('click' , '.editaj', function(){
            var id = $(this).data('id');
            
            $.ajax({
                type: "GET",
                url: baseUrl + 'detail-admin-device',
                data: ({id: id}),
                success: function(data){
                    $('.form-target').html(data);
                }
            });
            
            return false;
        });
        $(document).on('click' , '.cancelaj', function(){
            
            $.ajax({
                type: "GET",
                url: baseUrl + 'reset-admin-device',
                success: function(html){
                    //console.log(html);
                    $('.form-target').html(html);
                }
            });
            
            return false;
        });
        
        $(document).on('click' , '.deleteaj', function(){
            var f = confirm("Bạn muốn xóa tài khoản này");
            if(f){
                return true;
            }else{
                return false;
            }
        });
    });
    
    
    var checkpopup = 1;
    $(function()
    {
       $(document).on('click', '.close-map', function()
       {
            $("#box-map").hide();
            checkpopup = 1;
       });
    });
    
    $(document).on('change', '#address', function()
    {
        //checkpopup == 1;
        var txt = $(this).val();
        $(".show_msg").show();
       
            console.log('checkpopup', checkpopup);
            $("#box-map").css('display', 'table-row');    
        
        checkpopup = 2;
        
        setTimeout(function()
        {
            load();
            setTimeout(function()
            {
                showAddress(txt);  
            }, 1000);  
        }, 1000);
    });
</script>

<style type="text/css">
#box-map{
    display: none;
}
#box-map td{
    position: relative;
}
#box-map .close-map,
#box-map .show_msg{
    z-index: 999999;
    position: absolute;
    top: 14px;
    left: 3px;
    background: #FFF;
    padding: 6px;
    cursor: pointer;
    color: red;
}
#box-map .show_msg{
    left: auto;
    right: 20px;
    display: none;
}
</style>

<script src="http://maps.google.com/maps?file=api&amp;v=3&amp;key=ABQIAAAAgrj58PbXr2YriiRDqbnL1RSqrCjdkglBijPNIIYrqkVvD1R4QxRl47Yh2D_0C1l5KXQJGrbkSDvXFA" type="text/javascript"></script>
<script type="text/javascript">

function load() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    var center = new GLatLng(48.89364,  	2.33739);
    map.setCenter(center, 15);
    geocoder = new GClientGeocoder();
    var marker = new GMarker(center, {draggable: true});  
    map.addOverlay(marker);
    document.getElementById("lat").value = center.lat().toFixed(5);
    document.getElementById("lng").value = center.lng().toFixed(5);

  GEvent.addListener(marker, "dragend", function() {
    var point = marker.getPoint();
      map.panTo(point);
    document.getElementById("lat").value = point.lat().toFixed(5);
    document.getElementById("lng").value = point.lng().toFixed(5);

    });

  GEvent.addListener(map, "moveend", function() {
	  map.clearOverlays();
      var center = map.getCenter();
	  var marker = new GMarker(center, {draggable: true});
	  map.addOverlay(marker);
	  document.getElementById("lat").value = center.lat().toFixed(5);
      document.getElementById("lng").value = center.lng().toFixed(5);


  GEvent.addListener(marker, "dragend", function() {
     var point =marker.getPoint();
     map.panTo(point);
     document.getElementById("lat").value = point.lat().toFixed(5);
     document.getElementById("lng").value = point.lng().toFixed(5);

    });

    });

  }
}

function showAddress(address) {
   var map = new GMap2(document.getElementById("map"));
   map.addControl(new GSmallMapControl());
   map.addControl(new GMapTypeControl());
   if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
        } else {
                $(".show_msg").hide();                    
                document.getElementById("lat").value = point.lat().toFixed(5);
                document.getElementById("lng").value = point.lng().toFixed(5);
                map.clearOverlays()
                map.setCenter(point, 14);
                var marker = new GMarker(point, {draggable: true});  
                map.addOverlay(marker);
                
                GEvent.addListener(marker, "dragend", function() {
                    var pt = marker.getPoint();
                    map.panTo(pt);
                    document.getElementById("lat").value = pt.lat().toFixed(5);
                    document.getElementById("lng").value = pt.lng().toFixed(5);
                });
                GEvent.addListener(map, "moveend", function() {
                    map.clearOverlays();
                    var center = map.getCenter();
                    var marker = new GMarker(center, {draggable: true});
                    map.addOverlay(marker);
                    document.getElementById("lat").value = center.lat().toFixed(5);
                    document.getElementById("lng").value = center.lng().toFixed(5);
                    
                    GEvent.addListener(marker, "dragend", function() {
                        var pt = marker.getPoint();
                        map.panTo(pt);
                        document.getElementById("lat").value = pt.lat().toFixed(5);
                        document.getElementById("lng").value = pt.lng().toFixed(5);
                    });
                
                });
            }
        });
    }
}
</script>
 <script src="<?php echo $baseurl;?>assets/chosen_v1.4.2/chosen.jquery.js" type="text/javascript"></script>
  <script src="<?php echo $baseurl;?>assets/chosen_v1.4.2/prism.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript">
    var config = {
      '.chosen-select'           : {},
      '.chosen-select-deselect'  : {allow_single_deselect:true},
      '.chosen-select-no-single' : {disable_search_threshold:10},
      '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
      '.chosen-select-width'     : {width:"95%"}
    };
    for (var selector in config) {
      $(selector).chosen(config[selector]);
    }
  </script>
 

